import Taro, { Component} from '@tarojs/taro'
import '@tarojs/async-await'
import { Provider } from '@tarojs/redux'
import Index from './pages/index'
import configStore from './store'
import {http} from './modules'
import {reqId} from './config'
// import { token } from './actions/user'
import './app.scss'

const store = configStore();
class App extends Component {

  config = {
    pages: [
      'pages/index/index',
      'pages/demo/demo',
      'pages/component/components',
      'pages/photo/photo',
      'pages/cyht/cyht',
      'pages/chooseAdress/chooseAdress',
      'pages/chooseQz/chooseQz',
      'pages/chooseHt/chooseHt',
      'pages/searchQz/searchQz',
      'pages/searchHt/searchHt',
      'pages/moreQz/moreQz',
      'pages/moreHt/moreHt',
      'pages/qzXq/qzXq',
      'pages/tzDetail/tzDetail',
      'pages/hfDetail/hfDetail',
      'pages/cyList/cyList',
      'pages/cyXq/cyXq',
      'pages/qzZl/qzZl',
      'pages/glQz/glQz',
      'pages/glCy/glCy',
      'pages/jyCy/jyCy',
      'pages/addJycy/addJycy',
      'pages/htXq/htXq',

    ],
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: 'WeChat',
      navigationBarTextStyle: 'black',
      enablePullDownRefresh:true,
      onReachBottomDistance:50
    },
    // tabBar: {
    //   color: 'red',
    //  selectedColor: 'red',
    //  /**
    //   * tab 的背景色
    //   */
    //  backgroundColor: 'yellow',
    //  /**
    //   * tabbar上边框的颜色， 仅支持 black/white
    //   * default: black
    //   */
    //  borderStyle: 'black',
    //  /**
    //   * tabar 的位置，可选值 bottom、top
    //   * default: 'bottom'
    //   */
    //  position: 'bottom',
    //   list: [
    //     {
    //       pagePath:  'pages/index/index',
    //       text: 'one',
    //     },
    //     {
    //       pagePath:  'pages/demo/demo',
    //       text: 'two',
    //     }
    //   ]
    // }
  }

  componentWillMount() {    
    console.log(store)
    // 获取code创建用户 
    Taro.getWeRunData({success(e) {
      console.log(e)
    }})
    Taro.login()
    .then(data =>{
      const {code} = data;
      console.log(code)
      http('/code', {code, id: reqId}, true)
      .then(json => {
        const {token, token_type} = json;
        console.log(`${token_type} ${token}`)
      })
      .catch(err => console.log(err.message))
    })
  }

  render () {
    return (
      <Provider store={store}>
        <Index />
      </Provider>
    )
  }
}

Taro.render(<App />, document.getElementById('app'))
